<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
namespace Admin\Model;
use Admin\Model\BaseModel;
/**
 *@todo 展会签到模型
 */

class ConfCodeModel extends BaseModel {
    
    /**
     * @todo 返回主键
     * @see \Think\Model::getPk()
     * @author PHP@妖孽 <mashengjie@hrbjjhh.com>
     */
    public function getPk(){
    	return 'code_id';
    }
    
    /**
     * @todo 签到
     * @author PHP@妖孽 <mashengjie@hrbjjhh.com>
     */
    public function sign(){
        $code_id = (int)I('code_id');
        $activity_id = (int)I('activity_id');
        $mobile_phone = trim(I('mobile_phone'));
        if($code_id ==0){
            $this->error = '二维码标识有问题.~';
            return false;
        }
        if($activity_id ==0){
            $this->error = '请选择活动.~';
            return false;
        }
      
        if (!preg_match("/^1[3-8][0-9]{9}$/",$mobile_phone)){
            $this->error ='手机号格式有问题';
            return false;
        }
        if(!empty($this->where(array('code_id'=>$code_id,'activity_id'=>$activity_id))->find())){
            $this->error ='该胸牌已绑定,不能再次进行绑定';
            return false;
        }
        $obj = D('Admin/Customer','Service');
        $customer_id=$obj->customerIsJoinActivity($activity_id,$mobile_phone,3,0);
        if(false == $customer_id){
            $this->error =$obj->getError();
            return false;
        }
//         if(!empty($this->where(array('activity_id'=>$activity_id,'customer_id'=>$customer_id))->find())){
//             $this->error ='该用户已签到,不能再次进行签到';
//             return false;
//         }
        $data=array('code_id'=>$code_id,'activity_id'=>$activity_id,'customer_id'=>$customer_id);//准备签到数据
        if(!$this->add($data)){
            $this->error =$this->getError();
            return false;
        }
//         if(!D('Admin/Activity','Service')->activitySign($activity_id,$customer_id)){
//             $this->error =D('Admin/Activity','Service')->getError();
//             return false;
//         }
        return true;

    }
}
